
#delimit;
set more off;

cd "C:\....\Replication files";
	
use "ENMI - replication.dta", clear;



#delimit;

	gen volatility2 = L1.pvote;
	gen volatility3= D1.volatility2;
	
	egen volality_lastelection = mean(volatility3), by(country year);

			gen volatility4 = L2.pvote;
	
	gen volatility5= D1.volatility4;
	replace volatility5= (volatility5 + volatility3)/2;
	
	egen volality_twoelections = mean(volatility5), by(country year);
		
		gen volatility6 = L3.pvote;
	
	gen volatility7= D1.volatility6;
	replace volatility7= (volatility5 + volatility7)/2;
	
	egen volality_twoelections2 = mean(volatility7), by(country year);
	
	 
	gen volatility8 = L4.pvote;
	
	gen volatility9= D1.volatility8;
	replace volatility9= (volatility9 + volatility7)/2;
	
	egen volality_twoelections3 = mean(volatility9), by(country year);
	
	 
	gen volatility10 = L5.pvote;
	
	gen volatility11= D1.volatility10;
	replace volatility11= (volatility9 + volatility11)/2;
	
	egen volality_fiveelections = mean(volatility11), by(country year);
	
	 drop volality_lastelection volality_twoelections2;
	 
xtreg pvote
	c.ensh_mi##i.inc_cab_l, fe robust;
	estimates store ml_simple;
	
	
		
xtreg pvote
	c.ensh_mi##i.inc_cab_l pvote_l
	c.GDPgrowth##i.inc_cab_l 
	
	c.moderate##i.inc_cab_l
 majelect volality_fiveelections 
  , fe robust  ;

estimates store ml_full_fe;	


				#delimit;
set more off;
xtreg pvote
	1.inc_cab_l#c.ensh_mi pvote_l c.GDPgrowth
	1.inc_cab_l#c.moderate 
	 majelect volality_fiveelections 
	 
  if inc_cab_l==1 , fe robust;
		
testnl _b[c.ensh_mi#1.inc_cab_l] == 0 ;

		estimates store ml_onlyincumbents_fe;
		
						#delimit;


xtreg pvote
	c.ensh_mi c.GDPgrowth pvote_l
	moderate
		 majelect 
	volality_fiveelections 
		if inc_cab_l==0 , fe robust ;
	
	testnl _b[c.ensh_mi] == 0 ;
	
		estimates store ml_onlyopposition_fe;
		
		



#delimit;
 esttab ml_onlyopposition_fe ml_onlyincumbents_fe  ml_full_fe 
 using "figures\Table A18 - electoral volatility.rtf", replace 
		b (%10.3f) se scalars("aic AIC" "bic BIC" "rmse Root Mean Squared Error" "ll Log-Likelihood" ) 
		obslast star(+ 0.10 * 0.05 ** 0.01 *** 0.001)
		label mtitles (  "Opposition" "Incumbents" "Full") nogaps
title (\label{})
		
		
order(ensh_mi 
1.inc_cab_l#c.ensh_mi 
moderate 
1.inc_cab_l#c.moderate 
GDPgrowth
1.inc_cab_l#c.GDPgrowth 
1.inc_cab_l 

majelect 	volality_fiveelections  pvote_l  _cons ) 

keep(ensh_mi 1.inc_cab_l 
1.inc_cab_l#c.ensh_mi GDPgrowth 
1.inc_cab_l#c.GDPgrowth 1.inc_cab_l#c.moderate 
moderate majelect 
pvote_l 	volality_fiveelections   _cons )  

coeflabels(
ensh_mi "ENMI"  
1.inc_cab_l "Incumbent"
1.inc_cab_l#c.ensh_mi "Incumbent X ENMI"
GDPgrowth "GDP Growth Rate" 
1.inc_cab_l#c.GDPgrowth "Incumbent X GDP Growth Rate"
1.inc_cab_l#c.moderate "Incumbent X Moderated Position"
moderate "Moderated Position"
majelect "Majoritarian Election"
pvote_l "% Vote{\sub t-1}"
	volality_fiveelections  "Electoral volatility"
_cons "Constant");


	
